package LeetCode.interview.in0207;

import java.util.HashSet;

public class Review1 {
    public ListNode getIntersectionNode(ListNode headA, ListNode headB) {
        HashSet<ListNode> set = new HashSet<>();
        ListNode a = headA;
        while (a != null){
            set.add(a);
            a = a.next;
        }
        ListNode b = headB;
        while (b != null){
            if (set.contains(b)){
                return b;
            }
            b = b.next;
        }
        return null;
    }
}
